using System;
using System.Data;
using System.Data.SqlClient;

namespace Yichalal
{
    public class SqlDataReaderHelper 
    {

        public string GetString(SqlDataReader r, string columnName, string defaultValue) {
            string result = defaultValue;
            if (r[columnName] != null)
                result = r[columnName].ToString();
            return result;
        }

        public int GetInt(SqlDataReader r, string columnName, int defaultValue)
        {
            int result = defaultValue;
            if (r[columnName] != null)
                int.TryParse(r[columnName].ToString(),out result);

            return result;
        }

        public bool GetBool(SqlDataReader r, string columnName, bool defaultValue)
        {
            bool result = defaultValue;
            if (r[columnName] != null)
                bool.TryParse(r[columnName].ToString(), out result);

            return result;
        }

        public DateTime GetDateTime(SqlDataReader r, string columnName, DateTime defaultValue)
        {
            DateTime result = defaultValue;
            if (r[columnName] != null)
                DateTime.TryParse(r[columnName].ToString(), out result);

            return result;
        }
    }
}
